package top.kaoshanji.p2ch09a;

import top.kaoshanji.u1constant.FileConstant;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 代码清单-p2ch09a-296页a：获取接口实现对象的工厂方法
 * author kaoshanji
 * ^_^
 * create time 2025/2/2 11:10
 */
public class ServiceFactory {

    public static Versionized getService(String className, String version) throws Exception {

        Path path = Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("p2ch09a296页a"), version);
        FileSystemClassLoader loader = new FileSystemClassLoader(path);

        Class<?> clazz = loader.loadClass(className);
        return (Versionized)clazz.newInstance();

    }



}
